// 主导航页面的JavaScript

document.addEventListener('DOMContentLoaded', function() {
    // 获取当前页面路径
    const currentPath = window.location.pathname;
    const filename = currentPath.split('/').pop();
    
    // 设置侧边栏活动状态
    setSidebarActive(filename);
    
    // 设置导航链接活动状态
    setNavLinksActive(filename);
    
    // 初始化搜索功能
    initSearch();
    
    // 初始化通知点击事件
    initNotifications();
    
    // 初始化设置点击事件
    initSettings();
});

// 设置侧边栏活动状态
function setSidebarActive(filename) {
    const sidebarLinks = document.querySelectorAll('.sidebar .nav-item');
    
    sidebarLinks.forEach(link => {
        const linkHref = link.getAttribute('href');
        if (linkHref === filename || 
            (filename === '' && linkHref === 'qd-display.html') || 
            (filename === 'index.html' && linkHref === 'qd-display.html')) {
            link.classList.add('active');
        } else {
            link.classList.remove('active');
        }
    });
}

// 设置导航链接活动状态
function setNavLinksActive(filename) {
    const navLinks = document.querySelectorAll('.navigation-links .nav-link, .secondary-nav .nav-link, .tertiary-nav .nav-link');
    
    navLinks.forEach(link => {
        const linkHref = link.getAttribute('href');
        if (linkHref === filename) {
            link.classList.add('active');
        } else {
            link.classList.remove('active');
        }
    });
}

// 初始化搜索功能
function initSearch() {
    const searchInput = document.querySelector('.search-bar input');
    if (!searchInput) return;
    
    searchInput.addEventListener('focus', () => {
        searchInput.parentElement.classList.add('active');
    });
    
    searchInput.addEventListener('blur', () => {
        searchInput.parentElement.classList.remove('active');
    });
    
    searchInput.addEventListener('keyup', (e) => {
        if (e.key === 'Enter') {
            // 实际项目中可以实现搜索功能
            console.log('搜索:', searchInput.value);
        }
    });
}

// 初始化通知点击事件
function initNotifications() {
    const notificationIcon = document.querySelector('.notification');
    if (!notificationIcon) return;
    
    notificationIcon.addEventListener('click', () => {
        // 实际项目中可以显示通知面板
        console.log('打开通知面板');
    });
}

// 初始化设置点击事件
function initSettings() {
    const settingIcon = document.querySelector('.setting');
    if (!settingIcon) return;
    
    settingIcon.addEventListener('click', () => {
        // 实际项目中可以显示设置面板
        console.log('打开设置面板');
    });
}

// 处理卡片悬停效果
const infoCards = document.querySelectorAll('.info-card');
infoCards.forEach(card => {
    card.addEventListener('mouseenter', () => {
        card.style.transform = 'translateY(-5px)';
        card.style.boxShadow = 'var(--shadow)';
    });
    
    card.addEventListener('mouseleave', () => {
        card.style.transform = '';
        card.style.boxShadow = 'var(--shadow-sm)';
    });
});

// 处理值卡片点击效果
const valueCards = document.querySelectorAll('.value-card');
valueCards.forEach(card => {
    card.addEventListener('click', () => {
        card.classList.add('highlight');
        setTimeout(() => {
            card.classList.remove('highlight');
        }, 300);
    });
}); 